package com.yzr.common.reflection.questsion;

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Date;

/**
 * @description CLASS 类结构信息
 * @author: yx-0173
 * @date: 2021-08-13 10:53
 **/
public class ClassStructure {

    public static void main(String[] args) throws Exception {

        Class<A> aClass = A.class;
        // 获取全类名
        System.out.println("全类名" + aClass.getName());
        // 获取简单类名
        System.out.println("简单类名" + aClass.getSimpleName());
        // 获取所有public修饰的属性
        Field[] fields = aClass.getFields();
        System.out.println("===========所有公开的字段============");
        for (Field field : fields) {
            System.out.println(field.getName());
        }
        // 获取所有属性
        Field[] declaredFields = aClass.getDeclaredFields();
        System.out.println("===========A所有字段============");
        for (Field declaredField : declaredFields) {
            System.out.println(declaredField.getName());
        }
        // 获取所有public修饰的方法
        Method[] methods = aClass.getMethods();
        System.out.println("===========所有公开的方法============");
        for (Method method : methods) {
            System.out.println(method.getName());
        }
        // 获取所有类中所有的方法
        Method[] declaredMethods = aClass.getDeclaredMethods();
        System.out.println("===========所有的方法============");
        for (Method method : declaredMethods) {
            System.out.println(method.getName());
        }
        // 获取类中所有public的构造器，以及父类的
        System.out.println("===========所有public的构造器============");
        Constructor<?>[] constructors = aClass.getConstructors();
        for (Constructor<?> constructor : constructors) {
            System.out.println(constructor.getName());
        }
        // 获取类中所有的构造器
        System.out.println("===========所有的构造器============");
        Constructor<?>[] declaredConstructors = aClass.getDeclaredConstructors();
        for (Constructor<?> constructor : declaredConstructors) {
            System.out.println(constructor.getName());
        }
        // 获取类所在包
        System.out.println("===========类所在包============");
        System.out.println(aClass.getPackage());
        // 获取父级Class类
        System.out.println("===========类的父级Class============");
        System.out.println(aClass.getSuperclass());
        // 获取本类的所有实现的接口
        System.out.println("===========获取本类的所有实现的接口============");
        Class<?>[] interfaces = aClass.getInterfaces();
        for (Class<?> anInterface : interfaces) {
            System.out.println(anInterface.getName());
        }
        // 获取类上的所有的注解
        System.out.println("===========获取类上的所有的注解============");
        Annotation[] annotations = aClass.getAnnotations();
        for (Annotation annotation : annotations) {
            System.out.println(annotation.annotationType());
            Class<? extends Annotation> aClass1 = annotation.getClass();
        }
    }
}

@Deprecated
class A extends B implements C {
    private String name;

    public Integer age;

    public Date birthDay;

    String message;

    public A() {
    }

    private A(String name, Integer age, Date birthDay, String message) {
        this.name = name;
        this.age = age;
        this.birthDay = birthDay;
        this.message = message;
    }

    private String getName() {
        return name;
    }


    public Integer getAge() {
        return age;
    }


    public Date getBirthDay() {
        return birthDay;
    }

    String getMessage() {
        return message;
    }

}

class B {

    private String bName;

    public Integer bAge;

    public Date bBirthDay;

    String bMessage;

    public B() {
    }

    private B(String bName, Integer bAge, Date bBirthDay, String bMessage) {
        this.bName = bName;
        this.bAge = bAge;
        this.bBirthDay = bBirthDay;
        this.bMessage = bMessage;
    }

    private String getbName() {
        return bName;
    }

    public Integer getbAge() {
        return bAge;
    }

    public Date getbBirthDay() {
        return bBirthDay;
    }

    String getbMessage() {
        return bMessage;
    }
}

interface C {

}
